import request from '../utils/request'

export const fetchUser = () => {
  return request({
    url: '/user/info',
    method: 'get',
  })
}

export const fetchUserList = (page = 1, size = 10, keyword = '') => {
  return request({
    url: '/user/list',
    method: 'get',
    params: {
      page,
      size,
      keyword,
    },
  })
}

export const deleteUser = id => {
  return request({
    url: `/user/${id}`,
    method: 'delete',
  })
}

export const createUser = form => {
  return request({
    url: '/user/add',
    method: 'post',
    data: form, // data 是关键字
  })
}

export const resetPassword = id => {
  return request({
    url: '/user/reset',
    method: 'post',
    data: { id },
  })
}

export const updatePassword = (oldPassword, newPassword) => {
  return request({
    url: '/profile/update',
    method: 'post',
    data: { oldPassword, newPassword },
  })
}
